package com.gl.saasservice.sys.controller;


import com.gl.framework.web.response.Result;
import com.gl.saasservice.sys.service.CardWarehouseService;
import com.gl.saasservice.sys.vo.CardWarehouseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.util.List;

/**
 * CPU卡库管理
 */
@Controller
@RequestMapping(path = "/cardWarehouse")
public class CardWarehouseController{
    @Autowired
    private CardWarehouseService cardWarehouseService;


    /**
     * 列表
     * @param token
     * @param vo
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public Result list(@RequestHeader String token,
                       CardWarehouseVo vo) {
        return cardWarehouseService.list(token, vo);
    }

    /**
     * 冻结内容
     * @param token
     * @param vo
     * @return
     */
    @GetMapping("/freezeContent")
    @ResponseBody
    public Result freezeContent(@RequestHeader String token,
                       CardWarehouseVo vo) {
        return cardWarehouseService.freezeContent(token, vo);
    }



    /**
     * 详情
     * @param token
     * @param vo
     * @return
     */
    @GetMapping("/info")
    @ResponseBody
    public Result info(@RequestHeader String token,
                                CardWarehouseVo vo) {
        return cardWarehouseService.info(token, vo);
    }

    /**
     * 删除四代智能锁单个用户CUP卡
     * @param token
     * @param id 四代智能锁CUP卡id
     * @return
     */
    @DeleteMapping("/deleteCpuCard/{id}")
    @ResponseBody
    public Result deleteCpuCard(@RequestHeader String token,
                                @PathVariable Long id) {
        return cardWarehouseService.deleteCpuCard(token, id);
    }

    /**
     * 添加卡
     * @param token
     * @param vo
     * @return
     */
    @PostMapping("/save")
    @ResponseBody
    public Result add(@RequestHeader String token,
                      @RequestBody CardWarehouseVo vo) {
        return cardWarehouseService.save(token, vo);
    }


    /**
     * 修改卡
     * @param token
     * @param vo
     * @return
     */
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestHeader String token,
                         @RequestBody CardWarehouseVo vo) {
        return cardWarehouseService.update(token, vo);
    }



    /**
     *  删除卡
     * @param token
     * @param ids
     * @return
     */
    @RequestMapping(value = "{ids}", method = RequestMethod.DELETE)
    @ResponseBody
    public Result delete(@RequestHeader String token,
                         @PathVariable List<Long> ids) {
        return cardWarehouseService.delete(token, ids);
    }


    /**
     *  解绑卡
     * @param token
     * @param id
     * @return
     */
    @GetMapping("/unbind")
    @ResponseBody
    public Result unbind(@RequestHeader String token, Long id) {
        return cardWarehouseService.unbind(token, id);
    }


    /**
     *  冻结卡
     * @param token
     * @param vo
     * @return
     */
    @PostMapping("/frozen")
    @ResponseBody
    public Result frozen(@RequestHeader String token,
                         @RequestBody CardWarehouseVo vo) {
        return cardWarehouseService.frozen(token, vo);
    }



    /**
     *  解冻卡
     * @param token
     * @param vo
     * @return
     */
    @PostMapping("/thaw")
    @ResponseBody
    public Result thaw(@RequestHeader String token,
                       @RequestBody CardWarehouseVo vo) {
        return cardWarehouseService.thaw(token, vo);
    }


    /**
     * 模板下载
     */
    @GetMapping("/downloadFile")
    public void downloadFile() {
        this.cardWarehouseService.downloadFile();
    }

    /**
     * 文本文件上传
     *
     * @param file
     * @return
     */
    @PostMapping("/file/exportLog")
    @ResponseBody
    public void exportLog(@RequestParam MultipartFile file )throws Exception {
        cardWarehouseService.exportLog(file);
    }


    /**
     * 智能锁房屋列表
     * @param search
     * @param bindType      绑定类型:1单位 2个人
     * @param type
     * @param communityId
     * @param buildId
     * @param unitId
     * @param roomNumber
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/lockList")
    @ResponseBody
    public Result lockList(
                           @RequestParam(value = "search", required = false) String search,
                           @RequestParam(value = "bindType") Integer bindType,
                           @RequestParam(value = "type", required = false) Integer type,
                           @RequestParam(value = "communityId", required = false) String communityId,
                           @RequestParam(value = "buildId", required = false) Long buildId,
                           @RequestParam(value = "unitId", required = false) Long unitId,
                           @RequestParam(value = "roomNumber", required = false) String roomNumber,
                           @RequestParam(value = "provinceId", required = false) Long provinceId,
                           @RequestParam(value = "cityId", required = false) Long cityId,
                           @RequestParam(value = "districtId", required = false) Long districtId,
                           @RequestParam(value = "streetId", required = false) Long streetId,

                           @RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize) {
        return cardWarehouseService.lockList(search, bindType, type, communityId, buildId, unitId, roomNumber,provinceId,cityId,districtId,streetId, pageNumber, pageSize);
    }




    /**
     * 授权用户列表
     * @param houseId
     * @return
     */
    @GetMapping("/lockAuth")
    @ResponseBody
    public Result lockAuth(@RequestParam(value = "houseId") String houseId) {
        return cardWarehouseService.lockAuth( houseId);
    }

    /**
     * 授权卡
     *
     * @param lockAuthId
     * @param lockId
     * @param type        卡类型：1身份证 2CPU卡
     * @param cardNumber
     * @param cardId
     * @param authType    设置方式：1永久 2时间期限 3次数
     * @param authType    设置方式：1永久 2时间期限 3次数
     * @param value
     * @return
     */
    @GetMapping("/authCard")
    @ResponseBody
    public Result authCard(@RequestParam(value = "lockAuthId") Long lockAuthId, @RequestParam(value = "lockId") Long lockId,
                                       @RequestParam(value = "type") Integer type, @RequestParam(value = "cardNumber") String cardNumber,
                                       @RequestParam(value = "cardId") String cardId, @RequestParam(value = "authType") Integer authType,
                                       @RequestParam(value = "value", required = false) Integer value) {
        return  cardWarehouseService.authCard(lockAuthId, lockId, type, cardNumber, cardId, authType, value);
    }

}
